import { axios } from '@/utils/request'

const api = {
  deleteRule: '/validate/rule/delete/',
  queryRule: '/validate/rule/queryWithFormulaAndBinds',
  saveRule: '/validate/rule/all/save',
  listRules: '/validate/rule/list',
  removeFormula: '/validate/rule/removeFormula',
  queryExecHistory: '/validate/rule-score/queryHistory',
  changeEnabled: '/validate/rule/changeEnabled'
}

export function deleteRule (id) {
  return axios({
    url: api.deleteRule + id,
    method: 'delete'
  })
}
export function listRules (params) {
  return axios({
    url: api.listRules,
    params: params,
    method: 'get'
  })
}

export function removeFormula (params) {
  return axios({
    url: api.removeFormula,
    params: params,
    method: 'delete'
  })
}

export function saveRule (rule) {
  return axios({
    url: api.saveRule,
    data: rule,
    method: 'post'
  })
}
export function queryRules (params, pageNum, pageSize) {
  if (!params) {
    params = {}
  }
  params.pageNum = pageNum
  params.pageSize = pageSize
  return axios({
    url: api.queryRule,
    params: params,
    method: 'get'
  })
}
export function queryExecHistory (params, pageNum, pageSize) {
  if (!params) {
    params = {}
  }
  params.pageNum = pageNum
  params.pageSize = pageSize
  return axios({
    url: api.queryExecHistory,
    params: params,
    method: 'get'
  })
}

export function changeEnabled (rule) {
  return axios({
    url: api.changeEnabled,
    data: rule,
    method: 'post'
  })
}
